/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package PasswrdChk02.Componentes;

import InterfacesPasswordChecker02.SequencialsFactory;


/**
 *
 * @author LABCCET
 */
public class Sequencias implements SequencialsFactory{
    String password;
    final String LITERAIS = "abcdefghijlmnopqrstuvwxyz";
    final String DIGITOS = "01234567890"; 

    public Sequencias(String password) {
        this.password = password;
    }
        
    @Override
   public int calcularSequenciasDeLiterais(){
       String senha = password.toLowerCase();
       int qtdeSeqLiterais =0;
       String literais = this.LITERAIS;
            for (int s=0; s < 22; s++) {//<==== Literais sequenciais
		String sFwd = literais.substring(s,s+3);
		String sRev = new StringBuffer(sFwd).reverse().toString();
                if (senha.indexOf(sFwd) != -1 || senha.indexOf(sRev) != -1) { 
                    qtdeSeqLiterais++;
                    }
		}
       return qtdeSeqLiterais;
   }
   
    @Override
   public int calcularSequenciaDeDigitos(){
      return this.calcularSequencias( this.DIGITOS );        
   }
    
    @Override
   public int calcularSequenciaDeSimbolos(){       
       return this.calcularSequencias( new Simbolos().getSIMBOLOS() ); 
   } 

    private int calcularSequencias(String comparacao){
        int qtdeSeqDigitos = 0;
        for (int s=0; s < 8; s++) {
            String sFwd = comparacao.substring(s,s+3);
            String sRev = new StringBuffer(sFwd).reverse().toString();
            if (password.toLowerCase().indexOf(sFwd) != -1 || password.toLowerCase().indexOf(sRev) != -1) { 
                qtdeSeqDigitos++; 
            }
        }
        
        return qtdeSeqDigitos;
    }

}
